#include "Validator.h"
#include <opencv2/opencv.hpp>

class ValidatorWithROI : virtual public Validator
{
private:
    string roi_dir;

protected:
    virtual int *get_fincon_coordinates(const palmprint &p) const
    {
        return NULL;
    }

    virtual void get_roi_coordinates(const palmprint &p, int fincon[6], int Sx[4], int Sy[4]) const
    {
    }

    virtual uchar *get_roi(const palmprint &p, int Sx[4], int Sy[4]) const
    {
        auto get_roi_directly = [](const palmprint &p, int Sx[4], int Sy[4]) -> uchar * {
            const int roi_size = 128;
            uchar *roi_data = new uchar[roi_size * roi_size * sizeof(uchar)];
            cv::Mat roi;

            cv::resize(p.img, roi, cv::Size(roi_size, roi_size));

            // cv::imshow("roi", roi);
            // cv::waitKey(0);

            memcpy(roi_data, roi.data, roi_size * roi_size * sizeof(uchar));
            return roi_data;
        };

        return get_roi_directly(p, Sx, Sy);
    }

public:
    ValidatorWithROI(Database &db, string roi_dir);
    ~ValidatorWithROI();
};

ValidatorWithROI::ValidatorWithROI(Database &db, string roi_dir) : Validator(db), roi_dir(roi_dir)
{
}

ValidatorWithROI::~ValidatorWithROI()
{
}
